import java.util.Stack;

public class MInStack {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MInStack() {
        stack1 = new Stack<Integer>();
        stack2 = new Stack<Integer>();
    }

    public void push(int val) {
        stack1.push(val);
        if(stack2.isEmpty()) {
            stack2.push(val);
        }else {
            if(val <= stack2.peek()) {
                stack2.push(val);
            }
        }
    }

    public void pop() {
        int ret = stack1.pop();
        if(ret == stack2.peek()) {
            stack2.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }
}
